package com.hightemperator.controller;


import com.alibaba.fastjson.JSONObject;
import com.hightemperator.po.*;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.apache.http.HttpResponse;
import org.apache.http.util.EntityUtils;

import com.alibaba.fastjson.JSON;
import com.hightemperator.service.UserService;
import com.hightemperator.util.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.*;

@RestController
@RequestMapping("/api/user")
public class UserController {

    @Autowired
    public UserService userService;


    /**
     * 发送验证码接口
     *
     * @param request
     * @param phone             电话号码
     * @param type（0为注册，1为忘记密码）
     * @return
     */
    @RequestMapping("doSendCode")
    public LocalResponseBody doSendCode(HttpServletRequest request,
                                        @RequestParam("phone") String phone,
                                        @RequestParam(value = "type", defaultValue = "0") String type) {

        List<SysUserAndAuthentication> record = this.userService.getByMobile(phone);

        if (type.equals("0")) {
            if (record != null && record.size() > 0) {
                return new LocalResponseBody("操作失败,手机号已经注册").doFail();
            }
        } else {
            if (record == null || record.size() == 0) {
                return new LocalResponseBody("操作失败,用户不存在").doFail();
            }
        }

        String validate_code = CommonUtil.getRandom4();
        request.getSession().getServletContext().setAttribute(phone, validate_code);
        //发送短信代码 免费测试 已经调通 因测试数量不多暂时注释
        SendVerificodeUtil.sendVerificode(phone, validate_code);
        System.out.println(validate_code);
        return new LocalResponseBody("操作成功").doSuccess();

    }


    /**
     * 验证验证码是否正确
     * @param request
     * @param validateCode
     * @param mobile
     * @return
     */
    @RequestMapping("validateCodeFlag")
    public LocalResponseBody validateCodeFlag(HttpServletRequest request,
                                              @RequestParam(value = "validateCode")String validateCode,
                                              @RequestParam(value = "mobile")String mobile){
        String sessionCode = (String) request.getSession().getServletContext().getAttribute(mobile);
        if (sessionCode.equals(validateCode)){
            return new LocalResponseBody("操作成功").doSuccess();
        }else{
            return new LocalResponseBody("操作失败").doFail();
        }
    }

    /**
     * 注册 修改密码
     *
     * @param request
     * @param sysuser
     * @param type       类型 type=0注册type=1修改密码
     * @return
     */
    @RequestMapping(value = "addUser")
    public LocalResponseBody addUser(HttpServletRequest request, SysUser sysuser,
                                     @RequestParam(value = "type", required = true) String type,
                                     @RequestParam(value = "mobile",required = false)String mobile) {

        if (type.equals("0")) {
            Date d = new Date();
            sysuser.setCreatetime(d);
            sysuser.setUid(CommonUtil.getOrderNo());
        }

        sysuser.setPassword(MD5Util.MD5Encode(sysuser.getPassword(), "UTF-8"));
        int successCode = userService.addUser(sysuser,type);
        if (successCode == 0)
            return new LocalResponseBody("添加失败").doFail();

        return new LocalResponseBody("操作成功").doSuccess();
    }


    /**
     * 登录
     *
     * @param mobile   注册手机号
     * @param password 密码（需要md5加密）
     * @param wxId     为后期添加三方登录保留
     * @return
     */
    @RequestMapping("login")
    public LocalResponseBody login(HttpServletRequest request,
            HttpServletResponse response, @RequestParam(value = "mobile", required = false) String mobile,
                                   @RequestParam(value = "password", required = false) String password,
                                   @RequestParam(value = "wxId", required = false) String wxId) {

        if (mobile != null && !mobile.equals("")) {

            List<SysUserAndAuthentication> user = userService.getByMobile(mobile);
            if (user.size() == 0) {
                return new LocalResponseBody("操作失败").doFail();
            }
            SysUserAndAuthentication sysUser = user.get(0);
            String s = MD5Util.MD5Encode(password, "UTF-8");
            System.out.println(JSON.toJSONString(sysUser).toLowerCase());
            String token = getOfToken.setUserMessageString(sysUser.getUid(), request, JSON.toJSONString(sysUser).toLowerCase());

            if (user.size() > 0 && sysUser.getPassword().equals(s)) {
                sysUser.setPassword("");
                sysUser.setToken(token);
                sysUser.setPhotowall(handleRequestUrl(sysUser.getPhotowall(), request, "picture"));
                System.out.println(sysUser.getPhotowall());
                return new LocalResponseBody("登录成功").doSuccess(sysUser);
            } else {
                return new LocalResponseBody("操作失败").doFail();
            }
        }
        return new LocalResponseBody("请填写手机号").doFail();

    }


    /**
     * 添加认证
     *
     * @param files
     * @param type  1 车辆认证 2 学历认证 3 头像认证 4 房产认证 5 工作认证
     * @return
     */
    @RequestMapping("authenticationMessage")
    public LocalResponseBody authenticationMessage(HttpServletRequest request,
                                                   @RequestParam(value = "files", required = false) MultipartFile[] files,
                                                   @RequestParam(value = "type") String type) {
        String path;
        String token = request.getParameter("token");
        Integer uId = getOfToken.getUserMessageString(token, request);
        String tomcatPath = System.getProperty("catalina.home");
        int successCode = 0;
        if (type.equals("1")) {
            path = "car";
            String filePath = UploadUtil.uploadFileToPath(files, tomcatPath + Constant.SPEADER + "picture", path);
            if (filePath.length() == 0) {
                return new LocalResponseBody("操作失败").doFail();
            }
            successCode = userService.addAuthenticationCar(handleShowPhoto("", filePath, path), uId);
        } else if (type.equals("2")) {
            path = "education";
            String filePath = UploadUtil.uploadFileToPath(files, tomcatPath + Constant.SPEADER + "picture", path);
            if (filePath.length() == 0) {
                return new LocalResponseBody("操作失败").doFail();
            }
            successCode = userService.addAuthenticationEducation(handleShowPhoto("", filePath, path), uId);
        } else if (type.equals("3")) {
            path = "headimage";
            String filePath = UploadUtil.uploadFileToPath(files, tomcatPath + Constant.SPEADER + "picture", path);
            if (filePath.length() == 0) {
                return new LocalResponseBody("操作失败").doFail();
            }
            successCode = userService.addAuthenticationHeadimage(handleShowPhoto("", filePath, path), uId);
        } else if (type.equals("4")) {
            path = "house";
            String filePath = UploadUtil.uploadFileToPath(files, tomcatPath + Constant.SPEADER + "picture", path);
            if (filePath.length() == 0) {
                return new LocalResponseBody("操作失败").doFail();
            }
            successCode = userService.addAuthenticationHouse(handleShowPhoto("", filePath, path), uId);
        } else if (type.equals("5")) {
            path = "job";
            String filePath = UploadUtil.uploadFileToPath(files, tomcatPath + Constant.SPEADER + "picture", path);
            if (filePath.length() == 0) {
                return new LocalResponseBody("操作失败").doFail();
            }
            successCode = userService.addAuthenticationJob(handleShowPhoto("", filePath, path), uId);
        }
        if (successCode == 0) {
            return new LocalResponseBody("操作失败").doFail();
        }
        return new LocalResponseBody("操作成功").doSuccess();
    }


    /**
     * 通过id或微信id查询用户
     *
     * @param uId  用户id
     * @param wxId 用户的微信id
     * @return
     */
    @RequestMapping("getUserById")
    public LocalResponseBody getUserById(HttpServletRequest request,
                                         @RequestParam(value = "uId", required = false, defaultValue = "") Integer uId,
                                         @RequestParam(value = "wxId", required = false) String wxId) {

        String token = request.getParameter("token");
        Integer loginUserId = getOfToken.getUserMessageString(token, request);
        uId = (uId == null || uId.equals("")) ? loginUserId : uId;
        List<SysUserAndAuthentication> sysUsers = userService.getUserAllMessage(uId, wxId, loginUserId);
        if (sysUsers.size() > 0) {
            SysUserAndAuthentication sysUser = sysUsers.get(0);
            sysUser.setShowphoto(handleRequestUrl(sysUser.getShowphoto(), request, "picture"));
            sysUser.setHeadimage(handleRequestUrl(sysUser.getHeadimage(),request,"picture/userheadimage"));
            return new LocalResponseBody<SysUserAndAuthentication>("查询成功").doSuccess(sysUsers.get(0));
        } else {
            return new LocalResponseBody<SysUserAndAuthentication>("查询失败").doFail();
        }
    }


    /**
     * 通过id或微信id更新用户信息
     * 整个我的页面的信息都是靠这个借口更改 更改什么数据需要传确定的字段
     * 写多个借口 太麻烦 具体功能差不多 因此合并
     *
     * @param wxId 用户的微信id
     * @return
     */
    @RequestMapping("updateUser")
    public LocalResponseBody updateUser(
            SysUser sysUser,
            HttpServletRequest request,
            @RequestParam(value = "wxId", required = false) String wxId
    ) {

        String token = request.getParameter("token");
        Integer uId = getOfToken.getUserMessageString(token, request);
        List<SysUser> sysUsers = userService.getUserById(uId, wxId);

        if (sysUsers.size() > 0) {

            boolean isMultipart = ServletFileUpload.isMultipartContent(request);

            if (isMultipart) {
                MultipartFile files = ((MultipartHttpServletRequest) request).getFile("files");
                MultipartFile photoWall = ((MultipartHttpServletRequest) request).getFile("photoWall");
                MultipartFile headImageFile = ((MultipartHttpServletRequest) request).getFile("headImageFile");

                if (photoWall != null) {
                    String tomcatPath = System.getProperty("catalina.home");
                    String path = UploadUtil.uploadFileToPath(new MultipartFile[]{photoWall},
                            tomcatPath + Constant.SPEADER + "picture", "photoWall");
                    sysUser.setPhotowall(handleShowPhoto(sysUsers.get(0).getPhotowall(), path, "photoWall"));
                }

                if (headImageFile != null) {
                    String tomcatPath = System.getProperty("catalina.home");
                    String path = UploadUtil.uploadFileToPath(new MultipartFile[]{headImageFile},
                            tomcatPath + Constant.SPEADER + "picture", "userheadimage");
                    sysUser.setHeadimage(handleShowPhoto(sysUsers.get(0).getPhotowall(), path, "userheadimage"));
                }

                if (files != null) {
                    String tomcatPath = System.getProperty("catalina.home");
                    String path = UploadUtil.uploadFileToPath(new MultipartFile[]{files}, tomcatPath, "picture");
                    sysUser.setShowphoto(handleShowPhoto(sysUsers.get(0).getPhotowall(), path, "picture"));
                }
            }
            sysUser.setUid(uId);
            int successCode = userService.updateUser(sysUser);
            if (successCode == 0)
                return new LocalResponseBody("添加失败").doFail();
            else
                return new LocalResponseBody("添加成功").doSuccess();

        } else {
            return new LocalResponseBody<SysUser>("用户信息读取出错").doFail();
        }
    }


    /**
     * 获取关注列表
     *
     * @param uId  登陆用户的id
     * @param type 1为我关注的 2为关注我的 3为我拉黑的 4为拉黑我的（4暂时不会用到）5.互相关注列表
     * @return
     */
    @RequestMapping("getAttentionUserList")
    public LocalResponseBody getAttentionUserList(@RequestParam(value = "uId", required = false) Integer uId,
                                                  @RequestParam(value = "type", required = true) String type) {

        switch (type) {
            //用户的关注列表
            case "1": {
                List<SysUserAttention> userAttentions = userService.getAttentionList(uId);
                return new LocalResponseBody("操作成功").doSuccess(userAttentions);
            }
            //用户的被关注列表
            case "2": {
                List<SysUserAttention> userAttentions = userService.getBeAttentionList(uId);
                return new LocalResponseBody("操作成功").doSuccess(userAttentions);
            }
            //相互关注列表
            case "5": {
                List<SysUserAttention> userAttentions = userService.getBeAttentionList(uId);
                return new LocalResponseBody("操作成功").doSuccess(removeDuplicate(userAttentions));
            }
            //我拉黑的列表
            case "3": {
                List<Blacklist> blackListMessage = userService.getBlackListMessage(uId);
                return new LocalResponseBody("操作成功").doSuccess(blackListMessage);
            }

        }
        return new LocalResponseBody("操作失败").doFail();
    }


    /**
     * 添加关注
     *
     * @param sysUserAttention 用户关注实体
     * @return
     */
    @RequestMapping("addAttention")
    public LocalResponseBody addAttention(SysUserAttention sysUserAttention) {
        int successCode = userService.addAttention(sysUserAttention);
        if (successCode == 0) {
            return new LocalResponseBody("操作失败").doFail();
        }
        return new LocalResponseBody("操作成功").doSuccess();
    }

    /**
     * 添加黑名单
     *
     * @param blacklist 黑名单实体
     * @return
     */
    @RequestMapping("addBlackList")
    public LocalResponseBody addBlackList(Blacklist blacklist) {
        int successCode = userService.addBlackList(blacklist);
        if (successCode == 0) {
            return new LocalResponseBody("操作失败").doFail();
        }
        return new LocalResponseBody("操作成功").doSuccess();
    }


    /**
     * 上传 身份证正反面图片
     *
     * @param frontPath
     * @param reverseSide
     * @param phone
     * @return
     */
    @RequestMapping("verificationImage")
    public LocalResponseBody verificationImage(@RequestParam(value = "front", required = false) MultipartFile[] frontPath,
                                               @RequestParam(value = "reverseSide", required = false) MultipartFile[] reverseSide,
                                               @RequestParam(value = "phone") String phone) {

        String tomcatPath = System.getProperty("catalina.home");
        Identity identity = new Identity();
        if (frontPath != null) {
            String filePath = UploadUtil.uploadFileToPath(frontPath, tomcatPath + Constant.SPEADER + "picture" + Constant.SPEADER + "idCard", phone);
            filePath = filePath.replaceAll("/", "\\\\");
            String frontRealPath = tomcatPath + Constant.SPEADER + "picture" + Constant.SPEADER + "idCard" + Constant.SPEADER + filePath;
            if (filePath.length() > 0) {
                identity.setFrontPath(frontRealPath);
                return new LocalResponseBody("操作成功").doSuccess(identity);
            }
        }
        if (reverseSide != null) {
            String filePath = UploadUtil.uploadFileToPath(reverseSide, tomcatPath + Constant.SPEADER + "picture" + Constant.SPEADER + "idCard", phone);
            filePath = filePath.replaceAll("/", "\\\\");
            String reverseRealPath = tomcatPath + Constant.SPEADER + "picture" + Constant.SPEADER + "idCard" + Constant.SPEADER + filePath;
            if (filePath.length() > 0) {
                identity.setReverseSide(reverseRealPath);
                return new LocalResponseBody("操作成功").doSuccess(identity);
            }
        }
        return new LocalResponseBody("操作失败").doFail();
    }


    /**
     * 上传身份证图片验证是否为实名认证
     *
     * @param frontPath       身份证正面 服务器地址
     * @param reverseSidePath 身份证反面 服务器地址
     * @return
     */
    @RequestMapping("verificationIdentity")
    public LocalResponseBody verificationIdentity(@RequestParam(value = "frontPath") String frontPath,
                                                  @RequestParam(value = "reverseSidePath") String reverseSidePath) {


        String IDcardMessage = identityCard(frontPath);
        System.out.println(IDcardMessage);
        if (IDcardMessage.length() > 0) {
            String authenticationPerson = authenticationPerson(IDcardMessage);
            if (authenticationPerson.equals("0")) {
                return new LocalResponseBody("匹配成功").doSuccess();
            }
        }

        return new LocalResponseBody("操作失败").doSuccess();
    }


    /**
     * 添加举报
     *
     * @param file   举报图片
     * @param report 举报实体
     * @return
     */
    @RequestMapping("addReport")
    public LocalResponseBody addReport(@RequestParam("file") MultipartFile[] file,
                                       Report report) {

        String tomcatPath = System.getProperty("catalina.home");
        String filePath = UploadUtil.uploadFileToPath(file, tomcatPath + Constant.SPEADER, "report");

        if (filePath.length() == 0) {
            return new LocalResponseBody("操作失败").doFail();
        }
        report.setImagepath(handleShowPhoto("", filePath, "report"));
        int successCode = userService.addReport(report);
        if (successCode == 0) {
            return new LocalResponseBody("操作失败").doFail();
        }

        return new LocalResponseBody("操作成功").doSuccess();
    }


    /**
     * 获取举报列表
     *
     * @param uId 用户id
     * @return
     */
    @RequestMapping("getReportList")
    public LocalResponseBody getReportList(@RequestParam(value = "uId") Integer uId) {
        List<Report> reports = userService.getReportList(uId);
        return new LocalResponseBody("操作成功").doSuccess(reports);
    }


    /**
     * 根据登陆用户id获取充值记录列表
     *
     * @param uId 用户id
     * @return
     */
    @RequestMapping("getPayRecord")
    public LocalResponseBody getPayRecord(@RequestParam(value = "uId") Integer uId) {
        List<SysPayRecord> records = userService.getPayRecord(uId);
        return new LocalResponseBody("操作成功").doSuccess(records);
    }

    /**
     * 根据用户id 设置免打扰模式
     *
     * @param uId 用户id
     * @return
     */
    @RequestMapping("noDisturbing")
    public LocalResponseBody noDisturbing(@RequestParam(value = "uId") Integer uId) {

        int successCode = userService.updateNoDisturbing(uId);
        if (successCode == 0) {
            return new LocalResponseBody("操作失败").doFail();
        }
        return new LocalResponseBody("操作成功").doSuccess();
    }

    /**
     * 删除动态或者活动
     * @param activityOrCircleId 动态或者活动的id
     * @param type 类型 0为活动 1为动态
     * @return
     */
    @RequestMapping("deleteCircleOrActivity")
    public LocalResponseBody deleteCircleOrActivity(@RequestParam(value = "activityOrCircleId", defaultValue = "") Integer activityOrCircleId,
                                       @RequestParam(value = "type") String type){

        int successCode = userService.deleteCircleOrActivity(activityOrCircleId,type);
        if(successCode == 0){
            return new LocalResponseBody("操作失败").doFail();
        }
        return new LocalResponseBody("操作成功").doSuccess();
    }

    /**
     * 获取用户当前的免打扰状态
     *
     * @param uId
     * @return
     */
    @RequestMapping("getUserNoDisturbing")
    public LocalResponseBody getUserNoDisturbing(@RequestParam(value = "uId") Integer uId) {
        String noDisturbing = userService.getUserNoDisturbing(uId);
        return new LocalResponseBody("操作成功").doSuccess(noDisturbing);
    }


    /**
     * 获取身份证图片上的信息
     *
     * @param filePath
     * @return
     */
    public String identityCard(String filePath) {

        System.out.println(filePath.split(",")[0]);
        String base64 = Img2Base64Util.getImgStr(filePath.split(",")[0]);

        //读取身份证图片信息
        String host = "http://idcardocr.market.alicloudapi.com";
        String path = "/id_card_ocr";
        String method = "POST";
        String appcode = "481305592e1e4451b1d522755832dee2";
        Map<String, String> headers = new HashMap<String, String>();
        headers.put("Authorization", "APPCODE " + appcode);
        headers.put("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
        Map<String, String> querys = new HashMap<String, String>();
        Map<String, String> bodys = new HashMap<String, String>();
        bodys.put("imgData", base64);
        bodys.put("type", "1");

        try {
            HttpResponse response = HttpUtils.doPost(host, path, method, headers, querys, bodys);
            JSONObject json1 = JSON.parseObject(EntityUtils.toString(response.getEntity()));//全部数据（含状态数据、人数据）
            System.out.println("sss====:" + json1);
            JSONObject json2 = JSON.parseObject(json1.getString("showapi_res_body"));//人数据（含头像数据）
            return json2.toString();

        } catch (Exception e) {
            e.printStackTrace();
        }

        return "";

    }


    /**
     * 根据用户名身份证号获取是否为档案中存在的人
     *
     * @param idCardMessage
     * @return
     */
    public String authenticationPerson(String idCardMessage) {

        JSONObject json = JSON.parseObject(idCardMessage);
        String name = json.getString("name");
        String cardNum = json.getString("idNo");

        String host = "http://idcard.market.alicloudapi.com";
        String path = "/lianzhuo/idcard";
        String method = "GET";
        String appcode = "481305592e1e4451b1d522755832dee2";
        Map<String, String> headers = new HashMap<String, String>();
        //最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
        headers.put("Authorization", "APPCODE " + appcode);
        Map<String, String> querys = new HashMap<String, String>();
        querys.put("cardno", cardNum);
        querys.put("name", name);

        try {
            //处理该人是否存在的返回结果解析
            HttpResponse response = HttpUtils.doGet(host, path, method, headers, querys);
            JSONObject json1 = JSON.parseObject(EntityUtils.toString(response.getEntity()));//全部数据（含状态数据、人数据）
            JSONObject json2 = JSON.parseObject(json1.getString("resp"));//是否匹配
            return json2.getString("code");
        } catch (Exception e) {
            e.printStackTrace();
        }

        return "";

    }


    /**
     * 将返回的图片地址 拼接为可访问的url
     *
     * @param url
     * @return
     */
    public static String handleRequestUrl(String url, HttpServletRequest request, String baseUrl) {

        if (url.length() == 0) {
            return "";
        }

        String path2 = new GetIp().getServerIp() + ":" + request.getLocalPort();
        String[] strings = url.split(",");

        StringBuffer sb = new StringBuffer();
        for (String str : strings) {
            if (sb.length() != 0) {
                sb.append(",");
            }
            sb.append(path2);
            baseUrl = baseUrl.replaceAll("\\\\", "/");
            sb.append("/" + baseUrl + "/");
            sb.append(Calendar.getInstance().get(Calendar.MONTH) + "/");
            sb.append(str);
        }

        return sb.toString();
    }


    /**
     * 根据身份证号获取 年龄
     *
     * @param personCard
     * @return
     */
    public int handleAge(String personCard) {

        int personCardYear = Integer.parseInt(personCard.substring(6, 10));
        int sysYear = Calendar.getInstance().get(Calendar.YEAR);

        return sysYear - personCardYear;

    }


    /**
     * 根据身份证号返回籍贯地区 到省或直辖市
     *
     * @param personCard
     * @return
     */
    public String handleNativePlace(String personCard) {

        String codeAndCity[][] = {{"11", "北京"}, {"12", "天津"},
                {"13", "河北"}, {"14", "山西"}, {"15", "内蒙古"}, {"21", "辽宁"},
                {"22", "吉林"}, {"23", "黑龙江"}, {"31", "上海"}, {"32", "江苏"},
                {"33", "浙江"}, {"34", "安徽"}, {"35", "福建"}, {"36", "江西"},
                {"37", "山东"}, {"41", "河南"}, {"42", "湖北"}, {"43", "湖南"},
                {"44", "广东"}, {"45", "广西"}, {"46", "海南"}, {"50", "重庆"},
                {"51", "四川"}, {"52", "贵州"}, {"53", "云南"}, {"54", "西藏"},
                {"61", "陕西"}, {"62", "甘肃"}, {"63", "青海"}, {"64", "宁夏"},
                {"65", "新疆"}, {"71", "台湾"}, {"81", "香港"}, {"82", "澳门"},
                {"91", "国外"}};

        String firstTwoNum = personCard.substring(0, 2);

        for (String[] strs :
                codeAndCity) {
            if (strs[0].equals(firstTwoNum)) {
                return strs[1];
            }
        }

        return "查无此地";

    }

    /**
     * 拼接个人照片的url
     *
     * @param oldStr
     * @param newStr
     * @return
     */
    public static String handleShowPhoto(String oldStr, String newStr, String picturePath) {

        String[] strings = newStr.split(",");
        StringBuffer sb = new StringBuffer();
        int pathLength = picturePath.length() + 2;
        if (oldStr.length() > 0) {
            sb.append(oldStr);
        }

        if (newStr.length() > 0) {
            for (String path : strings) {
                String savePath = path.substring(Calendar.getInstance().get(Calendar.MONTH) > 9 ? pathLength : pathLength + 1, path.length());
                if (sb.length() != 0) {
                    sb.append(",");
                }
                sb.append(savePath);
            }
        }
        return sb.toString();
    }


    /**
     * 相互关注列表去重
     *
     * @param list
     * @return
     */
    public static List removeDuplicate(List<SysUserAttention> list) {

        for (int i = 0; i < list.size() - 1; i++) {
            for (int j = list.size() - 1; j > i; j--) {
                if (list.get(j).getUserid().equals(list.get(i).getUserid()) && list.get(j).getAttentionid().equals(list.get(i).getAttentionid())) {
                    list.remove(j);
                }
            }
        }
        return list;
    }


}